package com.zzyl.web.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.dto.ReservationDto;
import com.zzyl.nursing.domain.pojo.Reservation;
import com.zzyl.nursing.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 */
@Api(tags = "预约信息管理")
@RestController
@RequestMapping("/member/reservation")
public class ReservationController extends BaseController {
    @Autowired
    private IReservationService reservationService;

    /**
     * 2.1 查询当天取消预约数量
     */
    @ApiOperation("2.1 查询当天取消预约数量")
    @GetMapping("/cancelled-count")
    public AjaxResult getAllCancellerdCount() {
        Long count = reservationService.getAllCancellerdCount();
        return AjaxResult.success(count);
    }

//    //TODO 2.2 查询每个时间段剩余预约次数
//
//    @ApiOperation("2.2 查询每个时间段剩余预约次数")
//    @GetMapping("/countByTime")
//    public AjaxResult getReservationCount(long time) {
//        CountByTimeVo countByTimeVo = reservationService.getReservationCount(time);
//        return AjaxResult.success(countByTimeVo);
//    }

    /**
     * 2.3 新增预约
     */
    @ApiOperation("2.3 新增预约")
    @PostMapping
    public AjaxResult add(@RequestBody ReservationDto reservationDto) {
        reservationService.add(reservationDto);
        return AjaxResult.success();
    }


    /**
     * 2.4分页查询预约
     */
    @ApiOperation("2.4 分页查询预约")
    @GetMapping("/page")
    public R<TableDataInfo<List<Reservation>>> list() {
        startPage();
        List<Reservation> list = reservationService.selectReservationList();
        return R.ok(getDataTable(list));
    }


    /**
     * 2.5取消预约
     */
    @ApiOperation("2.5 取消预约")
    @PutMapping("{id}/cancel")
    public AjaxResult cancel(@PathVariable Long id) {
        reservationService.cancel(id);
        return AjaxResult.success();
    }

}
